import { ref, reactive } from "vue";
import { flow, household, important, reset_params } from "./request_params";
const input_idnum = ref();
const need_input = reactive([
  "/service/householdDeclaration_establishment",
  "/service/migration_establishment",
  "/service/householdlogout_establishment",
]);
const route_service = ref({
  1: "family_establishment",
  2: "collectively_establishment",
  3: "migration_establishment",
  4: "householdDeclaration_establishment",
  5: "householdlogout_establishment",
  6: "idcard_business",
  7: "important_info_collect",
  8: "important_info_change",
  9: "important_info_delect",
  10: "important_info_audit",
  11: "important_info_approval",
  12: "flow_collection",
  13: "flow_change",
  14: "flow_logout",
  15: "residence_permit_application",
  16: "police_station_management",
});
const Breadcrumb = reactive({
  sub_menu: "",
  menu_item: "",
});
const service = reactive({
  1: "常住人口管理",
  2: "重点人口管理",
  3: "流动人口管理",
  4: "派出所管理",
});
//菜单标题使用
const flow_menu_title = ref({
  1: "流动人口信息采集",
  2: "流动人口信息变更",
  3: "流动人口注销",
  4: "居住证申请",
});
const key_menu_title = ref({
  1: "重点人口信息采集",
  2: "重点人口信息变更",
  3: "重点人口注销",
  4: "重点人口信息审核",
  5: "重点人口信息审批",
});
const house_menu_title = ref({
  1: "家庭户口立户",
  2: "集体户口立户",
  3: "户口迁移",
  4: "户口申报",
  5: "户口注销",
  6: "身份证业务",
});
const police_menu_title = ref({
  1: "派出所管理",
});
const menu_title = ref({
  family_establishment: ["1", "家庭户口立户"],
  collectively_establishment: ["1", "集体户口立户"],
  migration_establishment: ["1", "户口迁移"],
  householdDeclaration_establishment: ["1", "户口申报"],
  householdlogout_establishment: ["1", "户口注销"],
  idcard_business: ["1", "身份证业务"],
  important_info_collect: ["2", "重点人口信息收集"],
  important_info_change: ["2", "重点人口信息变更"],
  important_info_delect: ["2", "重点人口信息注销"],
  important_info_audit: ["2", "重点人口信息审核"],
  important_info_approval: ["2", "重点人口信息审批"],
  flow_collection: ["3", "流动人口信息采集"],
  flow_change: ["3", "流动人口信息变更"],
  flow_logout: ["3", "流动人口注销"],
  residence_permit_application: ["3", "居住证申请"],
  police_station_management: ["4", "派出所管理"],
});
const handle_menu_click = (key) => {
  input_idnum.value = "";
  let menu = get_menu_index(key);
  if (menu.sub_menu == "1") {
    Breadcrumb.sub_menu = service[1];
    Breadcrumb.menu_item = house_menu_title.value[menu.menu_item];
  } else if (menu.sub_menu == "2") {
    Breadcrumb.sub_menu = service[2];
    Breadcrumb.menu_item = key_menu_title.value[menu.menu_item];
  } else if (menu.sub_menu == "3") {
    Breadcrumb.sub_menu = service[3];
    Breadcrumb.menu_item = flow_menu_title.value[menu.menu_item];
  } else if (menu.sub_menu == "4") {
    Breadcrumb.sub_menu = service[4];
    Breadcrumb.menu_item = police_menu_title.value[menu.menu_item];
  }
};
const get_menu_index = (index) => {
  let sub_index = index.indexOf("-") - 1;
  let menu_index = index.indexOf("-") + 1;
  return {
    sub_menu: index[sub_index],
    menu_item: index[menu_index],
  };
};
const init_Breadcrumb = (fullpath) => {
  let index_route = fullpath.lastIndexOf("/");
  if (index_route == 0) {
    return;
  }
  if (index_route + 1 !== fullpath.length) {
    let route = fullpath.substring(index_route + 1, fullpath.length);
    Breadcrumb.sub_menu = service[menu_title.value[route][0]];
    Breadcrumb.menu_item = menu_title.value[route][1];
  }
};
export {
  route_service,
  Breadcrumb,
  service,
  flow_menu_title,
  key_menu_title,
  house_menu_title,
  menu_title,
  handle_menu_click,
  get_menu_index,
  init_Breadcrumb,
  need_input,
  input_idnum,
  police_menu_title,
};
